﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>培训文件列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">培训计划管理</a><span lay-separator="">/</span>
            <a><cite>培训文件管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">&#x1002;</i>
        </a>
    </div>
    <div class="weadmin-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-row">
                    文件名称:
                    <div class="layui-inline">
                        <input type="text" id="sTFName" placeholder="文件名称" autocomplete="off" class="layui-input">
                    </div>
                    上传人员
                    <div class="layui-inline">
                        <input type="text" id="sTFAddUserName" placeholder="上传人员" autocomplete="off" class="layui-input">
                    </div>
                    上传时间
                    <div class="layui-inline">
                        <input type="text" class="layui-input" name="start" id="start">
                    </div>
                    -
                    <div class="layui-inline">
                        <input type="text" class="layui-input" name="end" id="end">
                    </div>

                </div>
            <!--</div>-->
            <!--<div class="layui-form-item">-->
                <div class="layui-row">
                    所属部门:
                    <div class="layui-inline">
                        <select id="DepID" name="DepID" class="valid" ></select>
                    </div>
                    审核状态:
                    <div class="layui-inline">
                        <select id="TFIsPass" name="TFIsPass" lay-verify="">
                            <option value=""></option>
                            <option value="0">未审核</option>
                            <option value="1">已审核</option>
                        </select>
                    </div>
                    删除状态:
                    <div class="layui-inline">
                        <select id="TFIsUse" name="TFIsUse" lay-verify="">
                            <option value=""></option>
                            <option value="1">未删除</option>
                            <option value="0">已删除</option>
                        </select>
                    </div>
                </div>
            </div>
        </form>
        <button class="layui-btn" id="sreach"><i class="layui-icon">&#xe615;  查询</i></button>
        <table id="datalist" lay-filter="datalist"></table>
    </div>
            <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="delAll"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>
                </div>
            </script>
            <script type="text/html" id="tool">
                <!--a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" >查看</a!-->
                <a class="layui-btn layui-btn-xs" lay-event="audit">审核</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                <a class="layui-btn layui-btn-xs" lay-event="queset">考题设置</a>
            </script>
            <script>
                layui.use(['table', 'jquery', 'layer', 'laydate', 'form'], function () {
                    var table = layui.table,
                        form = layui.form,
                        laydate = layui.laydate,
                        $ = layui.jquery,
                        layer = layui.layer;

                    //执行一个laydate实例
                    laydate.render({
                        elem: '#start',
                        trigger: 'click'
                    });
                    //执行一个laydate实例
                    laydate.render({
                        elem: '#end',
                        trigger: 'click'
                    });
                    $(function () {
                        console.log("init");
                        showList();
                        console.log("init end");
                        $("#sreach").click(function () {

                            console.log("click in ");
                            showList();
                        })
                    })

                    //加载部门信息，角色信息，机务段信息
                    $.ajax({
                        url: ApiUrl + "Dep/Sel",
                        type: 'post',
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                $("#DepID").append("<option value=''></option>");
                                $(data.Data).each(function (index, item) {
                                    $("#DepID").append("<option value='" + item.DepID + "'>" + item.DepName + "</option>");
                                });
                                form.render();//必须，不然动态加载项不显示
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    location.href = '../../login.html';
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });

                    //监听事件
                    table.on('toolbar(datalist)', function (obj) {
                        var checkStatus = table.checkStatus(obj.config.id);
                        switch (obj.event) {
                            case 'delAll':
                                if (checkStatus.data.length > 0) {
                                    var EIDs = "";
                                    for (var i = 0; i < checkStatus.data.length; i++) {
                                        EIDs += checkStatus.data[i].TFID + ",";
                                    }
                                    EIDs = EIDs.substring(0, EIDs.length - 1);
                                    $.ajax({
                                        url: ApiUrl + "TrainFiles/DelList",
                                        type: 'get',
                                        cache: false,
                                        headers: {
                                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                                        },
                                        data: { delidlist: EIDs },
                                        success: function (data) {
                                            if (data.StatusCode == 200) {
                                                layer.alert("删除成功", { icon: 6 }, function (index) {
                                                    layer.close(index);
                                                    location.reload();
                                                })
                                            }
                                            else if (data.StatusCode == 403) {
                                                layer.alert(data.Info, function () {
                                                    location.href = '../../login.html';
                                                })
                                            }
                                            else {
                                                layer.msg(data.Info);
                                            }
                                        }
                                    });
                                }
                                else {
                                    layer.msg("未找到勾选项！");
                                }
                                break;
                            case 'add':
                                var add = layer.open({
                                    type: 2,
                                    title: "培训文件添加",
                                    area: ['700px', '450px'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    content: './filemgr_add.html',
                                    end: function () {
                                        location.reload();
                                    }
                                });
                                layer.full(add);
                                break;
                        };
                    });
                    //监听工具条
                    table.on('tool(datalist)', function (obj) {
                        var data = obj.data; //获得当前行数据
                        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                        var tr = obj.tr; //获得当前行 tr 的DOM对象
                        if (layEvent === 'detail') { //查看
                            var detail = layer.open({
                                type: 2,
                                title: "文件信息详情",
                                area: ['700px', '450px'],
                                fixed: false, //不固定
                                maxmin: true,
                                content: './filemgr_detail.html?ID=' + data.EID,
                            });
                            layer.full(detail);
                        } else if (layEvent === 'del') { //删除
                            layer.confirm('确定要删除吗？', function (index) {
                                //向服务端发送删除指令
                                $.ajax({
                                    url: ApiUrl + "TrainFiles/Del",
                                    type: 'post',
                                    cache: false,
                                    headers: {
                                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                                    },
                                    data: data,
                                    success: function (data) {
                                        if (data.StatusCode == 200) {
                                            layer.alert("删除成功", { icon: 6 }, function (index) {
                                                layer.close(index);
                                                //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                                 
                                                obj.update({
                                                    IsDelete: '已删除'
                                                });
                                            })
                                        }
                                        else if (data.StatusCode == 403) {
                                            layer.alert(data.Info, function () {
                                                location.href = './login.html';
                                            })
                                        }
                                        else {
                                            layer.msg(data.Info);
                                        }
                                    }
                                });
                            });
                        } else if (layEvent === 'audit') { //审核
                            //向服务端发送审核指令
                            $.ajax({
                                url: ApiUrl + "TrainFiles/Audit",
                                type: 'get',
                                cache: false,
                                headers: {
                                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                                },
                                data: { tfid: data.TFID } ,
                                success: function (data) {
                                    if (data.StatusCode == 200) {
                                        layer.alert("审核成功", { icon: 6 }, function (index) {
                                            layer.close(index);
                                            obj.update({
                                                IsPass: '已审核'
                                            });
                                        })
                                    }
                                    else if (data.StatusCode == 403) {
                                        layer.alert(data.Info, function () {
                                            location.href = '../../login.html';
                                        })
                                    }
                                    else {
                                        layer.msg(data.Info);
                                    }
                                }
                            });
                        }
                        else if (layEvent === 'queset') { //编辑

                            var edit = layer.open({
                                type: 2,
                                title: "资料考题设置",
                                area: ['600px', '400px'],
                                fixed: false, //不固定
                                maxmin: true,
                                content: './filequestionmgr.html?TFID=' + data.TFID + '&TFName=' + data.TFName,
                                end: function () {
                                    location.reload();
                                }
                            });

                            layer.full(edit);
                        }
                    });

                    function showList() {
                        var swhere = JSON.stringify({
                            TFName: $("#sTFName").val().trim(),
                            TFAddUserName: $("#sTFAddUserName").val(),
                            TFUploadDeptID: $("#DepID").val(),
                            start: $("#start").val().trim(),
                            end: $("#end").val().trim(),
                            TFIsUse: $("#TFIsUse").val(),
                            TFIsPass: $("#TFIsPass").val(),
                        });

                        console.log("one run " + swhere);
                        table.render({
                            id: "datalist",
                            elem: '#datalist',
                            url: ApiUrl + 'TrainFiles/Search', //数据接口,
                            headers: {
                                "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                            },
                            where: { swhere: swhere },
                            cellMinWidth: 80,
                            toolbar: "#toolbar",
                            cols: [
                                [
                                    { type: 'checkbox' },
                                    { field: 'TFID', title: '编号', sort: true, hide: true },
                                    { field: 'TFName', title: '文件名称' },
                                    { field: 'FTName', title: '文件类型', width: 120 },
                                    { field: 'KKName', title: '知识点' ,width: 120},
                                    { field: 'TFPath', title: '文件位置', hide: true },
                                    { field: 'TFSize', title: '文件大小', width: 80, hide: true },
                                    { field: 'TFAddUserName', title: '上传人', width: 80 },
                                    { field: 'TFAddDateTime', title: '上传时间', width: 120 },
                                    { field: 'TFEndDateTime', title: '到期时间', width: 120 },
                                    { field: 'DepName', title: '所属部门', width: 100 },
                                    { field: 'TFFileLevel', title: '重要等级', width: 100 },
                                    { field: 'TFUseCount', title: '下载次数', hide: true },
                                    { field: 'IsPass', title: '是否审批', width: 90 },
                                    { field: 'IsDelete', title: '是否删除', width: 90 },
                                    { field: 'IsValid', title: '是否到期', width: 90 },
                                    { fixed: 'right', title: '操作', align: 'center', toolbar: '#tool', width: 230, }
                                ]
                            ],
                            parseData: function (res) { //res 即为原始返回的数据
                                return {
                                    "code": res.StatusCode, //解析接口状态
                                    "msg": res.Info, //解析提示文本
                                    "count": res.Count, //解析数据长度
                                    "data": res.Data //解析数据列表
                                };
                            },
                            response: { statusCode: 200 },//规定成功的状态码，默认：0
                            event: true,
                            page: true,
                            done: function (res, curr, count) {
                                //如果是异步请求数据方式，res即为你接口返回的信息。
                                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度 
                                if (res.code == 403) {
                                    layer.alert(res.msg, function () {
                                        top.location.href = '../../login.html';
                                    })
                                }
                            }
                        });
                    }
                });
            </script>
</body>
</html>